﻿using Authorization.Center.Controllers;
using Authorization.Center.SqlServer;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using S.PregnancyTest.API.Application.Command;

namespace S.PregnancyTest.API.Controllers
{
    /// <summary>
    /// 种母妊检添加、删除、修改
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PregnancyTestController : BaseController
    {

        private readonly IMediator mediator;

        public PregnancyTestController(IMediator mediator, MySqlDbContext db) : base(db)

        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 异步添加种母妊检 
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> AddAsyncPregnancyTest(PregnancyTestCreateCommand command)
        {
            command.addPregnancyTestDto.CreateBy = UserStrategyDto.UserTrueName;
            var i = await mediator.Send(command);
            return Ok(i);
        }


        /// <summary>
        /// 异步修改种母妊检信息
        /// </summary>
        /// <param name="comm"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> UpdatePregnancyTest(PregnancyTestUpdateCommand comm)
        {
            comm.UpdateBy = UserStrategyDto.UserTrueName; //将修改人设置为当前登录人
            return Ok(await mediator.Send(comm));
        }

        /// <summary>
        /// 删除种母妊检信息
        /// </summary>
        /// <param name="Ids"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> DeleteAllPregnancyTest(string Ids)
        {
            return Ok(await mediator.Send(new PregnancyTestDeleteCommand() { PregnancytestIds = Ids }));
        }

        /// <summary>
        /// 修改种母妊检耳号使用状态
        /// </summary>
        /// <param name="EarTag"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> UpdateSheepState(string EarTag)
        {
            return Ok(await mediator.Send(new UpdatePregnancyTestCommand() { EarTag = EarTag }));
        }

    }
}
